#!/bin/bash
##用于配置mariadb容器和phpmyadmin容器的脚本
rpmd=$(rpm -qa | grep docker)
if [ -z "$rpmd" ];then
        echo  -e "\033[1m 请先安装docker服务\033[5m"
else
	images=phpmyadmin
	source configure/install/docker/image-judge.sh
	images=mariadb
	source configure/install/docker/image-judge.sh
        echo 请输入数据库端口
        read dp
        echo 请输入数据库密码
        read dbpass
        docker run -d -p $dp:3306  -e MYSQL_ROOT_PASSWORD=$dbpass $(docker images|grep mariadb|awk '{print $1}')
        echo 请输入mariadb的容器名称[建议输入mariadb]
        read cname
        docker rename $(docker ps -a|awk 'NR==2{print}'|awk '{print $11}') $cname
        echo 已将mariadb容器名称改为$cname
        echo 请输入访问phpmyadmin服务的端口
        read php
        docker run -itd -p $php:80 --link $cname:db $(docker images|grep phpmyadmin|awk '{print $1}')
        echo 请输入phpmyadmin容器名
        read phpmyadmin
        docker rename $(docker ps -a|grep phpmyadmin |awk 'NR==1{print}'|awk '{print $13}') $phpmyadmin
        docker ps -a

fi


cat << EOF > dd
docker exec -it $cname /bin/bash
mysql -uroot -p$dbpass -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '$dbpass' WITH GRANT OPTION;
mysql -uroot -p$dbpass -e "flush privileges;"
EOF
cat dd
rm -rf dd